package com.example.tool.erp.demo;

import com.example.tool.erp.sdk.Client;
import com.example.tool.erp.sdk.Pager;
import com.example.tool.erp.sdk.api.sales.RawTradeAPI;
import com.example.tool.erp.sdk.api.sales.dto.RawTradeSearchHistoryRequest;
import com.example.tool.erp.sdk.api.sales.dto.RawTradeSearchHistoryResponse;
import com.example.tool.erp.sdk.impl.ApiFactory;
import com.example.tool.erp.sdk.impl.DefaultClient;

public class RawTrade
{
	public static void main(String[] args) throws Exception
	{
		// Client client = DefaultClient.get("wdtapi3", "test", "test");
		Client client = DefaultClient.get("wdterp30", "http://127.0.0.1:30000/", "zyOther",
				"423c25002f36c7445ccd7742ea5d1be4:8f034c5a36d5749a438951cde1963f2a");
		RawTradeAPI rawTradeAPI = ApiFactory.get(client, RawTradeAPI.class);

		rawTradeSearch(rawTradeAPI);
	}

	private static void rawTradeSearch(RawTradeAPI rawTradeAPI)
	{
		RawTradeSearchHistoryRequest request = new RawTradeSearchHistoryRequest();
		request.setStartTime("2023-03-01");
		request.setEndTime("2023-03-30");

		RawTradeSearchHistoryResponse response = rawTradeAPI.query(request, new Pager(1, 0, true));
		if (response.getTotal() <= 0)
		{
			System.out.println("No eligible results!");
			return;
		}

		for (RawTradeSearchHistoryResponse.OrderItem order : response.getOrders())
		{
			System.out.println(order.getTid() + " detail count:" + order.getTradeOrders().size() + " first detail:"
					+ order.getTradeOrders().get(0).getSpecNo());
		}
	}
}
